<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TL-CMS 模板安装</title>
    <script type="text/javascript" src="{{ url_for('static',filename='js/jquery.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static',filename='lib/layui/layui.all.js') }}"></script>
    <link rel="stylesheet" href="{{ url_for('static',filename='css/style.css') }}">
</head>
<body>
<form class="layui-form" style="padding-top: 20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">模板标识</label>
        <div class="layui-input-inline" style="width: 160px">
            <input class="layui-input" id="identifier" name="identifier" placeholder="输入模板标识" type="text" style="width: 100%">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn" id="submit" style="padding: 0 10px;background-color: #409eff;" onclick="submit_post()">确认安装</a>
            <a class="layui-btn" id="close" style="padding: 0 10px;margin-left: 0;background-color: #f56c6c;">取消安装</a>
        </div>
    </div>
</form>
<script>
    $(function () {

        $('#close').on('click', function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })
    });

    function submit_post() {
        var data = $("form").serializeArray();
        $.ajax({
            type: 'POST',
            data: data,
            dataType: "json",
            success: function (data) {
                if (data.status === 0) {
                    layer.msg('安装成功!', {icon: 1, time: 2000});
                    setTimeout(function () {
                        try {
                            var index = parent.layer.getFrameIndex(window.name);
                            window.parent.location.reload();
                            parent.layer.close(index);
                        } catch (e) {
                            console.debug('刷新异常')
                        }
                    }, 2000);
                } else {
                    layer.msg('安装失败: ' + data.msg, {icon: 2, time: 3000});
                }
            }, error: function (data) {
                layer.msg('安装失败!', {icon: 7, time: 2000});
            }
        });
        return status;
    }
</script>
</body>
</html>

